package com.flying.learning.si.sikg.client;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
public class WebController implements ApplicationContextAware {
    private ApplicationContext context;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.context = applicationContext;
    }

//    @Autowired
//    private GatewayConfig.Exchanger exchanger;

    @RequestMapping(path = "/foo/{other}", method = RequestMethod.GET)
    @ResponseBody
    public String foo(@PathVariable String other) {
        GatewayConfig.Exchanger exchanger = context.getBean(GatewayConfig.Exchanger.class);
        log.info("Controller received: " + other);
        String reply = exchanger.exchange(other);
        log.info("Controller replying: " + reply);
        return reply;
    }
}
